# 读取数据
import pandas as pd
data = pd.read_excel('订单表.xlsx', sheet_name=3, index_col=0)
print(data)

# 按标签选取行数据
a1 = data.loc['d002', :]
a2 = data.loc['d002':'d004', :]
a3 = data.loc[['d002', 'd004'], :]
print(a1)
print(a2)
print(a3)

# 按标签选取列数据
a4 = data.loc[:, '产品']
a5 = data.loc[:, '产品':'单价']
a6 = data.loc[:, ['产品', '数量', '单位']]
print(a4)
print(a5)
print(a6)

# 按标签选取区块数据
a7 = data.loc['d002':'d004', ['产品', '数量', '单位']]
print(a7)

# 按索引号选取行数据
b1 = data.iloc[1, :]
b2 = data.iloc[1:4, :]
b3 = data.iloc[[1, 3], :]
print(b1)
print(b2)
print(b3)

# 按索引号选取列数据
b4 = data.iloc[:, 0]
b5 = data.iloc[:, 0:3]
b6 = data.iloc[:, [0, 3, 1]]
print(b4)
print(b5)
print(b6)

# 按索引号选取区块数据
b7 = data.iloc[1:4, [0, 3, 1]]
print(b7)

# 快捷选取行数据
h = data.head(3)
t = data.tail(3)
print(h)
print(t)

# 快捷选取列数据
y1 = data['产品']
y2 = data[['产品', '数量', '单位']]
print(y1)
print(y2)
